#ifndef __DICTIONARY_H__
#define __DICTIONARY_H__

#include "AvlNode.h"

class Dictionary
{
	AvlNode* m_root;

	// private functions for the balance of the AVL
	int InsertHelper(AvlNode* newNode, AvlNode* root);
	void SingleRRotation(AvlNode* oldRoot, AvlNode* newRoot);
	void SingleLRotation(AvlNode* oldRoot, AvlNode* newRoot);
	void DoubleRLRotation(AvlNode* newLeftRoot, AvlNode* newRightRoot);
	void DoubleLRRotation(AvlNode* newLeftRoot, AvlNode* newRightRoot);
	void SwitchChild(AvlNode* parent, AvlNode* oldChild, AvlNode* newChild);
	AvlNode* MaxInTree(AvlNode* root);
	void CheckBalanceOfParents(AvlNode* node);
	void Rebalance(AvlNode** node, bool left, bool& h);

public:
	
	Worker* Find(StringKey *k);
	AvlNode* FindAvlNode(StringKey *k, AvlNode* root);
	int Insert(StringKey *k, Worker *d);
	Worker* Delete(StringKey *k);
	Worker* DeleteHelper(StringKey *k, AvlNode** subRoot, bool &h);
	void PrintDictionary();
	void PrintDictionaryRec(AvlNode* pNode); // recursive
	void FreeAllElementsRec(AvlNode* pNode); // recursive
	void FreeAllElements();
	bool IsEmpty() {return (m_root) ? false : true;}
	void DeleteDictionary(AvlNode* pNode);

	//Geters
	AvlNode* getRoot() {return m_root;}

	//C'tors and D'tors
	Dictionary(): m_root(NULL) {}
	virtual ~Dictionary();
};

#endif
